package com.lx.top.one;

import com.lx.entitys.CovidTopEntity;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: chenjiang
 * @Date: 2021/11/18/21:12
 * @Description: <br>
 *  1.
 * </br>
 */
public class CovidTopOneReducer extends Reducer<CovidTopEntity, NullWritable, CovidTopEntity, NullWritable> {
    @Override
    protected void reduce(CovidTopEntity key, Iterable<NullWritable> values, Context context) throws IOException, InterruptedException {
        /**
         * 不遍历迭代器，此时key就是分组中的第一个key 也就是该州确诊病例数最多的县对应的数据
         */
        //求Topone
//        context.write(key, NullWritable.get());
        //取topn
        long count = 0;
        for (NullWritable value : values) {
            if (count < 2) {
                context.write(key, NullWritable.get());
                count++;
            } else {
                return;
            }
        }
    }
}
